/**
 * 
 */
package com.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;

public class Loggable {

	public String toLogString() {
		Map<String, String> map = new LinkedHashMap<String, String>();
		for (Field field : this.getClass().getDeclaredFields()) {
			if (field.getName().equals("serialVersionUID"))
				continue;
			try {
				field.setAccessible(true);
				Object obj = field.get(this);
				map.put(field.getName(), obj == null ? null : obj.toString());
			} catch (IllegalArgumentException e1) {
				e1.printStackTrace();
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			}
		}
		if (this instanceof PropertiesCompatible) {
			try {
				Method md = this.getClass().getMethod("getProps");
				map.put("props:", (String) md.invoke(this));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return map.toString();
	}
}
